﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace TKT.Lifter.CIM.Lifter.TibcoMsg
{
    public abstract class MessageBody
    {
        public string MessageName { get; set; }

        public abstract XElement ToXElement();

        public abstract void Parse(XElement body);

        public MessageBody(string messageName)
        {
            this.MessageName = messageName;
        }

        public void Parse(TIBCO.Rendezvous.Message message)
        {
            TIBCO.Rendezvous.MessageField field = message.GetField("Message");
            if (field == null)
            {
                field = message.GetField("xmlData");
            }
            string strXML = field.Value as string;
            XElement root = XElement.Parse(strXML);
            XElement body = root.Element("Body");
            this.Parse(body);
        }
    }
}
